<!-- 资讯管理 -->
<template>
  <div class="app-container">
    <div class="container">
      <el-row>
        <el-form :inline="true" :model="listQuery">
          <el-form-item label="用户邮箱">
              <el-input v-model="listQuery.user" placeholder="用户邮箱" clearable  />
          </el-form-item>
          <el-form-item label="创建起始时间">
            <el-date-picker
                  v-model="listQuery.createTimeStart"
                  type="date"  value-format="YYYY-MM-DD"
                  placeholder="创建选择起始时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="结束时间">
            <el-date-picker
                  v-model="listQuery.createTimeEnd"
                  type="date"  value-format="YYYY-MM-DD"
                  placeholder="选择结束时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="状态">
            <el-select v-model="listQuery.status" placeholder="状态" clearable>
              <el-option v-for="item in Object.keys(statusDesc)" :label="statusDesc[item]" :key="item" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSearch">查询</el-button>
          </el-form-item>
        </el-form>
      </el-row>
      <el-row>
        <el-table :data="list"  v-loading="listLoading" element-loading-text="拼命加载中" border fit highlight-current-row>
          <el-table-column type="selection" width="55" align="center"></el-table-column>
          <el-table-column prop="userName" label="用户名" align="center"></el-table-column>
          <el-table-column prop="amount" label="金额" align="center"></el-table-column>
          <el-table-column prop="balance" label="余额" align="center"></el-table-column>
          <el-table-column prop="toAddress" label="目标地址" align="center"></el-table-column>
          <el-table-column prop="block" label="公链" align="center"></el-table-column>
          <el-table-column label="状态" width="145" align="center">
            <template #default="scope">
              <el-tag>{{ statusDesc[scope.row.state] }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="checkTime" label="支付日期" width="200" align="center"></el-table-column>
          <el-table-column prop="createTime" label="创建日期" width="200" align="center"></el-table-column>
          <el-table-column prop="updateTime" label="更新日期" width="200" align="center"></el-table-column>
        </el-table>

        <!-- 分页 -->
        <div class="pagination">
          <el-pagination
            layout="sizes, total, prev, pager, next"
            :page-sizes="[10, 20, 30]"
            v-model:page-size="listQuery.rows"
            v-model:currentPage="listQuery.page"
            @current-change="(val) => { fetchData() }"
            @size-change="(val) => { fetchData() }"
            :total="totalRecord"
          ></el-pagination>
        </div>
      </el-row>
    </div>
  </div>
</template>

<script>
import { queryRecharge } from '@/api/user'
import { utilsMixin } from '@/mixin/utils'
export default {
  name: 'UserRechargeList',
  mixins: [utilsMixin],
  data() {
    return {
      list: null, // 列表数据
      listLoading: true, // 加载状态
      totalRecord: 0, // 数据总条数
      listQuery: { page: 1, rows: 10 },
      listQueryParam: { page: 1 },
      statusDesc: {
        '0': '失败',
        '1': '成功'
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      queryRecharge(this.listQuery).then(response => {
        if (response.success && response.data != null) {
          this.list = response.data.records
          this.totalRecord = response.data.total
        }
        this.listLoading = false
      }).catch(() => {
        this.listLoading = false
      })
    },
    // 查询
    onSearch() {
      this.listQuery = Object.assign(this.listQuery, this.listQueryParam) // 合并对象
      this.fetchData()
    }
  }
}
</script>
